package com.lemon.blog.web.service.impl;

import com.lemon.blog.web.domain.BlTag;
import com.lemon.blog.web.mapper.BlTagMapper;
import com.lemon.blog.web.service.IBlTagService;
import com.lemon.common.core.exception.ServiceException;
import com.lemon.common.security.service.BaseServiceImpl;
import com.lemon.common.security.utils.OptEntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 包名称：com.lemon.blog.service.impl
 * 类名称：BlTagServiceImpl
 * 类描述：标签管理Service业务层处理
 * 创建人：@author huangpeng
 * 创建时间：2022-05-04
 */
@Service
public class BlTagServiceImpl extends BaseServiceImpl<BlTag> implements IBlTagService
{
    @Autowired
    private BlTagMapper blTagMapper;

    @Override
    public List<BlTag> selectBlTagList(BlTag blTag) {
        return blTagMapper.selectBlTagList(blTag);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insert(BlTag blTag) {
        BlTag tag = blTagMapper.selectBlTagByTagName(blTag.getTagName());
        if (tag != null){
            throw new ServiceException("标签已经存在");
        }
        OptEntityUtils.preInsert(blTag);
        blTag.setTagBlogCount(0);
        return blTagMapper.insertSelective(blTag);
    }

    @Override
    public List<BlTag> queryAllTag() {
        return blTagMapper.queryAllTag();
    }
}
